package com.all.seria.serialize.fst;

import com.all.seria.serialize.Serializer;
import org.nustaq.serialization.FSTConfiguration;

/**
 * @Author LY
 * @create 2024/5/10 17:52
 * @Description fst序列化与反序列化
 */
public class FstSerializer implements Serializer {

    @Override
    public <T> byte[] serialize(T obj) {
        if (obj == null){
            throw new RuntimeException("serialize object is null");
        }
        FSTConfiguration conf = FSTConfiguration.getDefaultConfiguration();
        return conf.asByteArray(obj);
    }

    @Override
    public <T> T deserialize(byte[] data, Class<T> cls) {
        if (data == null){
            throw new RuntimeException("deserialize data is null");
        }
        FSTConfiguration conf = FSTConfiguration.getDefaultConfiguration();
        return (T) conf.asObject(data);
    }
}
